import gradio as gr
import random
import datetime


def get_plot(seed=1):
    random.seed(seed)
    xstr = str(random.randint(0, 100))
    xstr += ' ' + str(seed)
    xstr += ' ' + str(datetime.datetime.now())
    return xstr


with gr.Blocks(analytics_enabled=False) as demo:
    with gr.Row():
        with gr.Column():
            gr.Markdown("Change the value of the slider to automatically update the plot")
            period = gr.Slider(label="Period of plot", value=1, minimum=0, maximum=10, step=1)
            text = gr.Textbox(interactive=False)

    # dep = demo.load(get_plot, None, text, every=1)
    # dep = demo.load(get_plot, period, text, every=0.2)
    dep = demo.load(get_plot, None, text)
    # period.change(get_plot, period, text, every=1, cancels=[dep])
    period.change(get_plot, period, text, every=0.2)
    period.change(get_plot, period, text)

# demo.queue().launch(server_name='0.0.0.0', server_port=7776, share=True)
demo.queue()
demo.launch(server_name='0.0.0.0', server_port=7771, share=True)
